#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Run backtest
import queue

class Backtest:
    def __init__(self, market_data_cls, **kwargs):
        self.event_queue = queue.Queue()
        self.market_data_cls = market_data_cls
        self._init_params(kwargs)

    def _init_params(self):
        # TODO: self.start_date, self.end_date, self.symbol
        if 'start_date' in kwargs.items():
            self.start_date = kwargs['start_date']
        if 'end_date' in kwargs.items():
            self.start_date = kwargs['end_date']
        

    def _init_instance(self):
        """ Initalize market data, strategy, portfolio, exchange class
        """
        self.market_data_instance = self.market_data_cls(self.event_queue, self.start_date, self.end_date, self.symbol)
    
    def run_backtest(self):
        md_engine = self.market_data_instance
        while True:
            if md_engine.publish_status:
                md_engine.publish()
                print(self.event_queue.pop())
            else:
                break